package com.retail.lottery.colalottery.controller;

import com.retail.lottery.colalottery.service.ColaAnswerRecordService;
import com.retail.lottery.colalottery.service.ColaQuestionBankService;
import com.retail.lottery.colalottery.vo.ResultVO;
import com.retail.lottery.colalottery.vo.request.ColeQuestionRequest;
import com.retail.lottery.colalottery.vo.request.QuestionAnswerListRequest;
import com.retail.lottery.colalottery.vo.request.QuestionAnswerRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/question")
@Slf4j
@Validated
public class ColaQuestionController {

    @Resource
    private ColaQuestionBankService colaQuestionBankService;

    @Resource
    private ColaAnswerRecordService colaAnswerRecordService;

    /**
     * 查询考题详情
     *
     * @param request
     * @return
     */
    @PostMapping("/detail")
    public ResultVO<?> queryQuestionDetailWithUserInfo(@Valid @RequestBody ColeQuestionRequest request) {
        return ResultVO.succ(colaQuestionBankService.queryQuestionDetailWithUserInfo(request));
    }

    /**
     * 保存考题结果
     *
     * @param answer
     * @return
     */
    @PostMapping("/answer")
    public ResultVO<?> answer(@Valid @RequestBody QuestionAnswerRequest answer) {
        return ResultVO.succ(colaAnswerRecordService.answerQuestion(answer));
    }

    /**
     * 查询考题答题历史
     *
     * @param answer
     * @return
     */
    @PostMapping("/answerHistory")
    public ResultVO<?> answerHistory(@Valid @RequestBody QuestionAnswerListRequest answer) {
        return ResultVO.succ(colaAnswerRecordService.answerHistory(answer));
    }
}
